package nf.com.crud.controller;

import nf.com.crud.entity.Test2;
import nf.com.crud.service.Test2Service;
import nf.com.crud.service.impl.Test2ServiceImpl;
import nf.com.crud.utils.JsonUtils;
import nf.com.crud.vo.ResponseVo;
import nf.com.crud.vo.Test2Vo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/update")
public class Test2UpdateController extends HttpServlet {
    Test2Service test2Service=new Test2ServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=UTF-8");
        Test2Vo vo= JsonUtils.read(req.getInputStream(),Test2Vo.class);
        Test2 test2=new Test2();
        test2.setUname(vo.getUname());
        test2.setId(vo.getId());

        test2Service.update(test2);

        ResponseVo responseVo=new ResponseVo(200,"修改成功",true);
        String s=JsonUtils.write(responseVo);
        resp.getWriter().println(s);
    }
}
